package Java8实战._2_Stream_使用流._2_映射;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class _3_测试3 {


    public static void main(String[] args) {

        /**
         * 只返回总和能被3整除的数对
         */
        List<Integer> list1 = Arrays.asList(1,2,3);
        List<Integer> list2 = Arrays.asList(3,4);

        List<int[]> collect = list1.stream()
                                    .flatMap(i -> list2.stream()
                                            .filter(j -> (i + j) % 3 == 0)
                                            .map(j -> new int[]{i, j})
                                    )
                                    .collect(Collectors.toList());

        //输出
        for (int i = 0; i < collect.size(); i++){
            System.out.print("(");
            for (int j = 0; j < collect.get(i).length; j++){
                System.out.print(collect.get(i)[j]);
                if(j != collect.get(i).length - 1){
                    System.out.print(",");
                }
            }
            System.out.print(")");
        }
    }

}
